//
//  WYWaltController.m
//  Boss
//
//  Created by admin on 2018/7/2.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYWaltController.h"
#import "WYPurseDetailController.h"
#import "WYWallet.h"
#import "WYPutForwardController.h"
@interface WYWaltController ()<UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIView *mainView;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topHeight;
@property (nonatomic,strong) WYWallet *wallet;

@property (strong, nonatomic) IBOutlet UILabel *blanceLabel;
@property (strong, nonatomic) IBOutlet UILabel *totalLabel;
@property (strong, nonatomic) IBOutlet UILabel *inviteLabel;
@property (strong, nonatomic) IBOutlet UILabel *redLabel;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *top1;


@property (strong, nonatomic) IBOutlet NSLayoutConstraint *top2;

@property (strong, nonatomic) IBOutlet UIButton *tixianBtn;



@end

@implementation WYWaltController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self.tixianBtn setCornerRadius:5.f];
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self loadData];
}
-(void)loadData
{
    WEAKSELF
    [WYHttpServer getUserWalletSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            weakSelf.wallet = [WYWallet getWalletModelFromJson:response[@"result"]];
            [weakSelf upDateUI];
        }
        
        
        
    }];
    
    
}
-(void)upDateUI
{
    self.totalLabel.text = [NSString stringWithFormat:@"%.3f",self.wallet.totalMoney.floatValue/1000.0];
    self.inviteLabel.text = [NSString stringWithFormat:@"%.3f",self.wallet.inviteMoney.floatValue/1000.0];
    self.blanceLabel.text = [NSString stringWithFormat:@"%.3f",self.wallet.balance.floatValue/1000.0];
    self.redLabel.text = [NSString stringWithFormat:@"%.3f",self.wallet.redMoney.floatValue/1000.0];
    
    
    
    
}
-(void)setupUI
{
    
    if (@available(iOS 11.0, *)) {
        [self.scrollView setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentNever)];
    } else {
        // Fallback on earlier versions
    }
    self.top1.constant = 100*DUP;
    self.top2.constant = 120*DUP;
    self.scrollView.delegate = self;
    
    
    self.topHeight.constant= self.navHeight;
    self.mainView.size = CGSizeMake(self.scrollView.width, self.scrollView.height);
    [self.scrollView addSubview:self.mainView];
    self.scrollView.contentSize = self.mainView.size;
    [self wr_setNavBarShadowImageHidden:YES];
    
    self.navigationItem.title = @"我的钱包";
    self.navigationItem.rightBarButtonItem  = [[UIBarButtonItem alloc]initWithTitle:@"明细" style:(UIBarButtonItemStylePlain) target:self action:@selector(rightBarButtonItemAction)];
    
    
}

-(void)rightBarButtonItemAction
{
    WYPurseDetailController *pvc = [[WYPurseDetailController alloc]init];
    [self.navigationController pushViewController:pvc animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)tixianAction:(id)sender {
    
    WYPutForwardController *pfc = [[WYPutForwardController alloc]init];
    if (self.wallet) {
        pfc.blance = self.wallet.balance;
        pfc.isWithdraw = self.wallet.isWithdraw;
        pfc.oneWithdraw = self.wallet.oneWithdraw;
    }
    [self.navigationController pushViewController:pfc animated:YES];
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint offset = scrollView.contentOffset;
    if (offset.y <= 0) {
        offset.y = 0;
    }
    scrollView.contentOffset = offset;
}
@end
